#include <stdio.h>
#include "defines.h"

/**
 * Forward declaration of our test functions
 */
void* testfunc1(void*);

/**
 *  Part C requires implementing support for timers
 */
int main()
{
    // make room for a bunch of uthreads
    THREAD_T tid[32];

    // Test #1: round-robin schedulinguthread_self in parent, parent concurrent with children
    int i;
    for (i = 1; i < 4; ++i) {
        THREAD_CREATE(&tid[i], testfunc1, (void*)i);
    }
    testfunc1(0);
    for (i = 1; i < 4; ++i) {
        THREAD_JOIN(tid[i], NULL);
    }

}

/**
 * This is just like test#5 of part D, except now we take out the yield.  It
 * should still work...
 */
void* testfunc1(void* params)
{
    // use this integer to coordinate among threads
    static volatile int pingpong = 0;
    int i;
    for (i = 0; i < 5; ++i) {
        while ((pingpong%4) != (int)params) { /* infinite loop */ }
        printf("Pingpong: thread %d (ID=%d) sees %d\n", (int)params, THREAD_SELF(), pingpong);
        pingpong++;
    }
    return NULL;
}
